<template>
  <div
    class="card"
    :class="sideTheme"
    :style="`flex-direction:${floatLeft ? 'row' : 'row-reverse'};`"
    @click="toDetail"
  >
    <div class="card-left">
      <img
        class="card-left-img"
        :class="floatLeft?'left-img':'right-img'"
        :src="`${data.img}`"
        alt=""
      />
    </div>
    <div class="card-right">
      <span class="card-title" :title="data.title">{{ data.title }}</span>
      <div class="meta-wrap">
        <span>
          <calendar-alt class="meta-icon" />
          <span>发表于 {{ data.createTime }}</span>
          <span class="meta-separator">|</span>
        </span>
        <span>
          <history class="meta-icon" />
          <span>更新于 {{ data.updateupTime }}</span>
          <span class="meta-separator">|</span>
        </span>
        <span>
          <tag class="meta-icon" />
          <span>{{ data.tag }}</span>
        </span>
      </div>
      <div class="content">
        {{ data.content }}
      </div>
    </div>
  </div>
</template>

<script setup lang="ts" name="Card">
import { CalendarAlt, History, Tag } from '@vicons/fa';
import { useSettingsStore } from '@/store';
import { useRouter } from 'vue-router';
import { toRefs, computed } from 'vue';
const router = useRouter();

const settingsStore = useSettingsStore();
const sideTheme = computed(() => settingsStore.sideTheme);

const props = defineProps({
  floatLeft: {
    type: Boolean,
    default: true,
  },
  data: {
    type: Object,
    default: () => {
      return {
        img: 'card_img.png',
        title:
          '获取街道、镇级的地图geoJson数据方法，使用echarts绘制出街道、镇级的地图区域画面（杭州市为例）',
        createTime: '',
        updateupTime: '',
        tag: '',
        content: '',
      };
    },
  },
});
const { data, floatLeft } = toRefs(props);

const toDetail = () => {
  if (data.value.route) {
    router.push({ name: data.value.route });
  }
};
</script>

<style lang="scss" scoped>
.card {
  display: flex;
  margin-top: 20px;
  background: rgba(255, 255, 255, 0.9);
  height: 18em;
  width: 100%;
  line-height: 2;
  border-radius: 8px;
  box-shadow: 0 3px 8px 6px rgba(7, 17, 27, 0.05);
  overflow: auto;
}

.card-left {
  width: 45%;
  height: 100%;
  overflow: hidden;
  & > .card-left-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    -webkit-transition: filter 375ms ease-in 0.2s, -webkit-transform 0.6s;
  }
}
.card-right {
  width: 55%;
  padding: 30px 40px;
  & > .card-title {
    font-size: 1.72em;
    line-height: 1.4;
    transition: all 0.2s ease-in-out;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
}
.meta-wrap {
  margin: 6px 0;
  color: #858585;
  font-size: 90%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  .meta-icon {
    width: 14px;
    height: 14px;
    color: #858585;
    margin-right: 4px;
    margin-bottom: -1px;
  }
  .meta-separator {
    display: inline-block;
    margin: 0 6px;
  }
}
.content {
  font-size: 15px;
  color: #4c4948;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.card:hover {
  .card-left-img {
    transform: scale(1.1);
  }
}
.card-title:hover {
  color: #80c8f8;
  cursor: url('../../assets/cur/x2.cur'), default;
}

.theme-dark {
  background: rgba(0, 0, 0, 0.5) !important;
  color: rgba(255, 255, 255, 0.9);
  .content {
    color: #ffffffb3;
  }
}
.left-img {
  border-radius: 8px 0 0 8px;
}
.right-img {
  border-radius: 0 8px 8px 0;
}
@media (max-width: 580px) {
  .card {
    flex-wrap: wrap;
    height: 380px;
    .card-left {
      width: 100%;
      height: 50%;
      .left-img {
        border-radius: 8px 8px 0 0;
      }
      .right-img {
        border-radius: 8px 8px 0 0;
      }
    }
    .card-right {
      width: 100%;
      height: 50%;
      .card-title {
        -webkit-line-clamp: 1;
      }
      .content {
        -webkit-line-clamp: 2;
      }
    }
  }
}
</style>
